package com.tian.excel.controller;

import com.tian.excel.vo.R;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: Tian
 * @version: 1.0
 * @since: 1.0
 * @date: 2024/7/27/15:20
 */
@RestController
public class LoginController {


    @PostMapping("/success")
    public R success(){
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication = context.getAuthentication();
        UserDetails principal = (UserDetails)authentication.getPrincipal();
        return new R(200,"登录成功", principal);
    }

    @PostMapping("/error1")
    public R error(){
        System.out.println("=================登录失败================");
        return new R(400,"登录失败", null);
    }
}
